<?php 

include "../../includes/functions.php";
echo db_connect();

$day = date("l"); //echo $day;

$query="SELECT s.show_id, so.start_time, so.end_time, so.id, s.name FROM show_occurrances so, shows s 
WHERE so.show_id = s.show_id
AND so.day_of_week = '$day'
AND s.status = 1 ORDER BY so.start_time";
$result= mysql_query($query);

 while ($row= mysql_fetch_array($result)) {
 		$show_id=$row['show_id'];
		$occ_id=$row['id']; 
		$show_name= addslashes ($row['name']);
		$start_time= substr($row['start_time'],0,5);
		$end_time= substr($row['end_time'],0,5);
		
		$insert_query = "INSERT INTO show_events (id, show_id, show_occurrance_id, show_name, start_time, end_time, `date`) VALUES ('','$show_id','$occ_id','$show_name','$start_time','$end_time',now())";
		echo $insert_query."<br>";
		$insert_result = mysql_query($insert_query);
		if (!$insert_result) die("error saving:".mysql_error()." ".$insert_query);
		
 }
 
?>